package com.song.service.impl;

import com.song.pojo.User;
import com.song.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author TonySong
 * @date 2024/5/24 0024
 * @time 17:20
 */
@Service
public class UserService implements IUserService {
    @Resource
    private RedisTemplate redisTemplate;

    private static  final  String KEY="users";
    @Override
    public Map<String, User> getAllUser() {
       return this.redisTemplate.opsForHash().entries(KEY);
    }

    @Override
    public void add(User user) {
          this.redisTemplate.opsForHash().put(KEY,user.getId()+"",user);
    }

    @Override
    public void delete(String key) {
       this.redisTemplate.opsForHash().delete(KEY,key);
    }
}
